The objective is to read the gender inequality data, get the difference between the inequality index in 2010 and 2019 respectively, then join it with the spatial data of the world, and then visualise it! So here goes
library(tidyverse)
library(sf)
library(janitor)
gender_ineq <- read_csv('hdr-data.csv')
global_map <- st_read('World_Countries_(Generalized)_9029012925078512962.geojson')
## Reading layer `World_Countries_(Generalized)_9029012925078512962' from data source `C:\Users\mkbs_\Documents\UCL\GI Systems and Science\Wk 4\CASA0005-Wk-4-Homework\World_Countries_(Generalized)_9029012925078512962.geojson'
## using driver `GeoJSON'
## Simple feature collection with 251 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -180 ymin: -89 xmax: 180 ymax: 83.6236
## Geodetic CRS: WGS 84
head(gender_ineq)
## # A tibble: 6 × 10
## countryIsoCode country indexCode index dimension indicatorCode indicator year
## <chr> <chr> <chr> <chr> <lgl> <chr> <chr> <dbl>
## 1 AFG Afghan… GII Gend… NA gii Gender I… 2010
## 2 AFG Afghan… GII Gend… NA gii Gender I… 2019
## 3 AGO Angola GII Gend… NA gii Gender I… 2010
## 4 AGO Angola GII Gend… NA gii Gender I… 2019
## 5 ALB Albania GII Gend… NA gii Gender I… 2010
## 6 ALB Albania GII Gend… NA gii Gender I… 2019
## # ℹ 2 more variables: value <dbl>, note <lgl>
head(global_map)
## Simple feature collection with 6 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -170.8232 ymin: -18.01639 xmax: 74.91574 ymax: 42.66035
## Geodetic CRS: WGS 84
## FID COUNTRY ISO COUNTRYAFF AFF_ISO geometry
## 1 1 Afghanistan AF Afghanistan AF MULTIPOLYGON (((61.27655 35...
## 2 2 Albania AL Albania AL MULTIPOLYGON (((19.57083 41...
## 3 3 Algeria DZ Algeria DZ MULTIPOLYGON (((4.603354 36...
## 4 4 American Samoa AS United States US MULTIPOLYGON (((-170.7439 -...
## 5 5 Andorra AD Andorra AD MULTIPOLYGON (((1.445836 42...
## 6 6 Angola AO Angola AO MULTIPOLYGON (((23.47611 -1...
We can see that the Gender Inequality data is given as a long table. We can also anticipate immediate difficulties when joining the two data frames, because the Gender Inequality data uses three-letter ISO codes but the Global Map data uses two-letter ISO codes.
We address the first issue - cleaning Gender Inequality data.
gender_ineq_diff <- gender_ineq %>%
pivot_wider(id_cols = 1:2,
names_from = year,
values_from = value) %>%
clean_names() %>%
mutate(diff = x2010 - x2019)
head(gender_ineq_diff)
## # A tibble: 6 × 5
## country_iso_code country x2010 x2019 diff
## <chr> <chr> <dbl> <dbl> <dbl>
## 1 AFG Afghanistan 0.704 0.676 0.0280
## 2 AGO Angola 0.556 0.536 0.0200
## 3 ALB Albania 0.192 0.131 0.061
## 4 ARE United Arab Emirates 0.165 0.039 0.126
## 5 ARG Argentina 0.37 0.283 0.087
## 6 ARM Armenia 0.352 0.216 0.136
Now we turn to joining the non-spatial data to the spatial data. This can be achieved by relying on the countrycode package, which should have been installed using Console directly (thus it would not be featured in this Markdown document)
library(countrycode)
gender_ineq_diff <- gender_ineq_diff %>%
mutate(iso_2letter = countrycode(gender_ineq_diff$country_iso_code, 'iso3c', 'iso2c'))
gender_ineq_map <- global_map %>%
left_join(.,
gender_ineq_diff,
by = c('ISO' = 'iso_2letter')) %>%
mutate(GII_2010 = x2010,
GII_2019 = x2019) %>%
select(c('COUNTRY', 'ISO', 'GII_2010', 'GII_2019', 'diff'))
head(gender_ineq_map)
## Simple feature collection with 6 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -170.8232 ymin: -18.01639 xmax: 74.91574 ymax: 42.66035
## Geodetic CRS: WGS 84
## COUNTRY ISO GII_2010 GII_2019 diff geometry
## 1 Afghanistan AF 0.704 0.676 0.028 MULTIPOLYGON (((61.27655 35...
## 2 Albania AL 0.192 0.131 0.061 MULTIPOLYGON (((19.57083 41...
## 3 Algeria DZ 0.508 0.385 0.123 MULTIPOLYGON (((4.603354 36...
## 4 American Samoa AS NA NA NA MULTIPOLYGON (((-170.7439 -...
## 5 Andorra AD NA NA NA MULTIPOLYGON (((1.445836 42...
## 6 Angola AO 0.556 0.536 0.020 MULTIPOLYGON (((23.47611 -1...
Now we can go ahead and map it!
library(tmap)
library(tmaptools)
tmap_mode('view')
tm_shape(gender_ineq_map) +
tm_polygons(fill="diff",
fill.scale= tm_scale_intervals(values="matplotlib.afmhot",
style="jenks"),
fill_alpha=0.5,
fill.legend = tm_legend(title = "Change in Index Rate",
size = 0.8)) +
tm_basemap(server = "OpenStreetMap") +
tm_scalebar(position = c("left", "bottom"))+
tm_title("Change in Gender Inequality Index from 2010 to 2019",
size = 2,
position = c("center", "top"))
Of course this map shows the CHANGE in Gender Inequality. Just because a country may have little change does not mean that it has not made a commitment towards achieving gender equality (look at some of the Western and Northern European countries). Click on the respective countries to find out more details such as the GII in 2010 and 2019!